package single_dispatch;

public class SingleDispatchDemo {

    /**
     * Single Dispatch
     *
     * 执行对象的哪个方法，根据编译时信息确定
     * 执行哪个对象的方法，根据运行时信息确定
     *
     * @param p
     */

    public void overloadFunction(ParentClass p) {
        System.out.println("decide by parameter type ParentClass");
        p.f();  //decide by p real type
    }

    public void overloadFunction(ChildClass p) {
        System.out.println("decide by parameter type ChildClass");
        p.f();  //decide by p real type
    }


    public static void main(String[] args) {
        SingleDispatchDemo demo = new SingleDispatchDemo();
        ParentClass parentClass = new ChildClass();
        demo.overloadFunction(parentClass);
    }



}
